// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file basic_structTypeObjectSupport.cxx
 * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file
 *
 * This file was generated by the tool fastddsgen.
 */

#include "basic_structTypeObjectSupport.hpp"

#include <mutex>
#include <string>

#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/xtypes/common.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>

#include "basic_struct.hpp"


using namespace eprosima::fastdds::dds::xtypes;

// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_TheOtherObject_type_identifier(
        TypeIdentifierPair& type_ids_TheOtherObject)
{

    ReturnCode_t return_code_TheOtherObject {eprosima::fastdds::dds::RETCODE_OK};
    return_code_TheOtherObject =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "TheOtherObject", type_ids_TheOtherObject);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_TheOtherObject)
    {
        StructTypeFlag struct_flags_TheOtherObject = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_TheOtherObject = "TheOtherObject";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_TheOtherObject;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_TheOtherObject;
        CompleteTypeDetail detail_TheOtherObject = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_TheOtherObject, ann_custom_TheOtherObject, type_name_TheOtherObject.to_string());
        CompleteStructHeader header_TheOtherObject;
        header_TheOtherObject = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_TheOtherObject);
        CompleteStructMemberSeq member_seq_TheOtherObject;
        {
            TypeIdentifierPair type_ids_some_num;
            ReturnCode_t return_code_some_num {eprosima::fastdds::dds::RETCODE_OK};
            return_code_some_num =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_int32_t", type_ids_some_num);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_some_num)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "some_num Structure member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            StructMemberFlag member_flags_some_num = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_some_num = 0x00000000;
            bool common_some_num_ec {false};
            CommonStructMember common_some_num {TypeObjectUtils::build_common_struct_member(member_id_some_num, member_flags_some_num, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_some_num, common_some_num_ec))};
            if (!common_some_num_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure some_num member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_some_num = "some_num";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_some_num;
            ann_custom_TheOtherObject.reset();
            CompleteMemberDetail detail_some_num = TypeObjectUtils::build_complete_member_detail(name_some_num, member_ann_builtin_some_num, ann_custom_TheOtherObject);
            CompleteStructMember member_some_num = TypeObjectUtils::build_complete_struct_member(common_some_num, detail_some_num);
            TypeObjectUtils::add_complete_struct_member(member_seq_TheOtherObject, member_some_num);
        }
        CompleteStructType struct_type_TheOtherObject = TypeObjectUtils::build_complete_struct_type(struct_flags_TheOtherObject, header_TheOtherObject, member_seq_TheOtherObject);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_TheOtherObject, type_name_TheOtherObject.to_string(), type_ids_TheOtherObject))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "TheOtherObject already registered in TypeObjectRegistry for a different type.");
        }
    }
}
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_basic_struct_type_identifier(
        TypeIdentifierPair& type_ids_basic_struct)
{

    ReturnCode_t return_code_basic_struct {eprosima::fastdds::dds::RETCODE_OK};
    return_code_basic_struct =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "basic_struct", type_ids_basic_struct);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_basic_struct)
    {
        StructTypeFlag struct_flags_basic_struct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_basic_struct = "basic_struct";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_basic_struct;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_basic_struct;
        CompleteTypeDetail detail_basic_struct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_basic_struct, ann_custom_basic_struct, type_name_basic_struct.to_string());
        CompleteStructHeader header_basic_struct;
        header_basic_struct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_basic_struct);
        CompleteStructMemberSeq member_seq_basic_struct;
        {
            TypeIdentifierPair type_ids_sub_struct;
            ReturnCode_t return_code_sub_struct {eprosima::fastdds::dds::RETCODE_OK};
            return_code_sub_struct =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "TheOtherObject", type_ids_sub_struct);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_sub_struct)
            {
            ::register_TheOtherObject_type_identifier(type_ids_sub_struct);
            }
            StructMemberFlag member_flags_sub_struct = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_sub_struct = 0x00000000;
            bool common_sub_struct_ec {false};
            CommonStructMember common_sub_struct {TypeObjectUtils::build_common_struct_member(member_id_sub_struct, member_flags_sub_struct, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_sub_struct, common_sub_struct_ec))};
            if (!common_sub_struct_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure sub_struct member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_sub_struct = "sub_struct";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_sub_struct;
            ann_custom_basic_struct.reset();
            CompleteMemberDetail detail_sub_struct = TypeObjectUtils::build_complete_member_detail(name_sub_struct, member_ann_builtin_sub_struct, ann_custom_basic_struct);
            CompleteStructMember member_sub_struct = TypeObjectUtils::build_complete_struct_member(common_sub_struct, detail_sub_struct);
            TypeObjectUtils::add_complete_struct_member(member_seq_basic_struct, member_sub_struct);
        }
        CompleteStructType struct_type_basic_struct = TypeObjectUtils::build_complete_struct_type(struct_flags_basic_struct, header_basic_struct, member_seq_basic_struct);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_basic_struct, type_name_basic_struct.to_string(), type_ids_basic_struct))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "basic_struct already registered in TypeObjectRegistry for a different type.");
        }
    }
}

